import ajaxAsync, { getUserInfo } from 'vue-xiaobu-utils'

/**
 * 获取云卡申请的身份信息, 返回不脱敏的信息
 *
 * @returns
 */
async function getVCardApplyInfo() {
  let rs = await ajaxAsync('/vcard/applyinfo/get', { IS_DESENSITIZATION: 0 })
  if (rs.CARD_OWNER && rs.ID_CARD_NUMBER) {
    return [rs.CARD_OWNER, rs.ID_CARD_NUMBER]
  } else {
    throw new Error('no userinfo')
  }
}

/**
 * 无需人工审核的申请云卡
 * @param {String} name 用户名称
 * @param {String} id 用户身份证号
 * @param {String} cardInstanceId 卡实例编号
 * @param {String} phone 手机号
 */
function applyCardWithoutVerify(
  name,
  id,
  cardInstanceId = 'jhx_buscard',
  phone = getUserInfo().PHONE
) {
  let postData = {
    CARD_OWNER: name,
    ID_CARD_NUMBER: id,
    PHONE_NO: phone,
    CARD_INSTANCE_ID: cardInstanceId
  }
  let postUrl = window.busCardApplyPostUrl || '/vcard/apply/no_auth'
  return ajaxAsync(postUrl, postData, 1)
}
export { getVCardApplyInfo, applyCardWithoutVerify }
